package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.pojo.MemberCard;
import com.woniu.service.IMemberCardService;
import com.woniu.vo.MemberCardQueryVo;
import com.woniu.vo.QueryMemberCardVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xie
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/memberCard")
@Api(tags = "会员绑定会员卡管理")
public class MemberCardController extends BaseController{

    @Autowired
    IMemberCardService service;

    @ApiOperation("条件分页查询")
    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result queryByItemInPage(@PathVariable long currentPage, @PathVariable long pageSize,
                                    @RequestBody MemberCardQueryVo vo){
        PageResult result=service.queryByItemInPage(currentPage,pageSize,vo);
        return toDataResult(result);
    }

    @ApiOperation("通过id查找")
    @GetMapping("/{id}")
    public Result queryById(@PathVariable String id){
        QueryMemberCardVo vo=service.queryById(id);
        return toDataResult(vo);
    }

    @ApiOperation("修改费用/次数")
    @PutMapping("/{id}/{account}")
    public Result addMoney(@PathVariable int account, @PathVariable String id){
        int row=service.addMoney(account,id);
        return toResult(row);
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id){
        boolean flag = service.removeById(id);
        return toResult(flag);
    }

}
